/*
 * Внеземные цивилизации
 * vim:foldmethod=marker:
 */

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#define MIN(a,b)	((a) < (b) ? (a) : (b))

char *
strcat_ign(char *dest, const char *src, char ignore)
{
	char *ret = dest;

	while (*dest)
		++dest;
	do {
		if (*src != ignore) {
			*dest++ = *src;
		}
		++src;
	} while (*src);

	*dest = '\0';

	return ret;
}

long *
z_func(const char *s, long s_len)
{
	long *z;
	int i, l, r;

	z = (long *) malloc(s_len * sizeof *z);
	memset(z, 0, s_len * sizeof *z);

	for (i = 1, l = 0, r = 0; i < s_len; ++i) {
		if (i <= r)
			z[i] = MIN(r - i + 1, z[i - l]);
		while (i + z[i] < s_len && s[z[i]] == s[i + z[i]])
			++z[i];
		if (i + z[i] - 1 > r)
			l = i, r = i + z[i] - 1;
	}

	return z;
}

long *
substr_frq(const long *z, const long substr_length, const long text_length)
{
	long	*a;
	register long i;
	long	accumulated = 0;

	a = (long *) calloc(substr_length, sizeof *a);

	for (i = 0; i < text_length; ++i)
		if (z[i] - 1 >= 0)
			++a[z[i] - 1];
	for (i = substr_length - 1; i > 0; --i)
		a[i - 1] += a[i];

	return a;
}

int
main(void)
{
	char	*text, *s, *buf;
	char	*p;
	long	*z;
	long	*ssv;
	long	substr_length;
	int	i = 0, j = 0;

	fprintf(stderr, "sizeof (long)=%zu\n", sizeof (long));

	text = (char *) malloc(200002UL * sizeof *text);
	s = (char *) malloc(400002UL * sizeof *s);
	buf = (char *) malloc(600005UL * sizeof *buf);
	buf[0] = '\0';

	(void) fgets(text, 2000001UL, stdin);
	(void) fgets(s, 400001UL, stdin);

	if ((p = strchr(text, '\n')))
		*p = '\0';
	if ((p = strchr(s, '\n')))
		*p = '\0';

	strcat_ign(buf, s, '?');
	substr_length = strlen(buf);
	strcat(buf, "#");
	strcat(buf, text);

	z = z_func(buf, strlen(buf));
	ssv = substr_frq(z + substr_length + 1, substr_length, strlen(text));

	while (s[i]) {
		if (s[i] == '?')
			printf("%ld\n", ssv[i - ++j]);
		++i;
	}

	free(ssv);
	free(z);
	free(buf);
	free(s);
	free(text);

	return 0;
}
